import BasicLayout from '@/layouts/BasicLayout';
import UserLayout from '@/layouts/UserLayout';
import React, { lazy } from 'react';

// import NotFound from '@/components/NotFound'; // 页面没找到

import Dashboard from '@/pages/Dashboard';
import Login from '@/pages/user/Login';
import PhoneLogin from '@/pages/user/PhoneLogin';
import Register from '@/pages/user/Register';
import ResetPassword from '@/pages/user/ResetPassword';

import BusOrder from '@/pages/order/BusOrder';
import OtherRefund from '@/pages/order/Other';
import CcOrder from '@/pages/order/CcOrder';
import ScOrder from '@/pages/order/ScOrder';
import RsOrder from '@/pages/order/RsOrder';
import Ticket from '@/pages/order/Ticket';
import DayCcOrder from '@/pages/order/DayCcOrder';
import CcTask from '@/pages/task/CcTask';
import ScTask from '@/pages/task/ScTask';
import RsTask from '@/pages/task/RsTask';
import Trip from '@/pages/company/Trip';
import CompanyInfo from '@/pages/company/CompanyInfo';
import Dispatcher from '@/pages/company/Dispatcher';
import Driver from '@/pages/company/Driver';
import Vehicle from '@/pages/company/Vehicle';
import BusStation from '@/pages/price/BusStation';
import BusPrice from '@/pages/price/BusPrice';
import LineTime from '@/pages/price/LineTime';
import RoadStation from '@/pages/price/RoadStation';
import CcPrice from '@/pages/price/CcPrice';
import CcStation from '@/pages/price/CcStation';
import CcStationGroup from '@/pages/price/CcStationGroup';
import Port from '@/pages/price/Port';
import Region from '@/pages/price/Region';
import ScPrice from '@/pages/price/ScPrice';
import ScSharePrice from '@/pages/price/ScSharePrice';
import ScSelfPrice from '@/pages/price/ScSelfPrice';
import ScRelevancy from '@/pages/price/ScRelevancy';
import ScStation from '@/pages/price/ScStation';
import OtherStation from '@/pages/price/OtherStation';
import Surcharge from '@/pages/price/Surcharge';
import Activity from '@/pages/market/Activity';
import ActivityCharts from '@/pages/market/Activity/components/Charts';
import Coupon from '@/pages/market/Coupon';
import Scene from '@/pages/market/Scene';
// import UserSelector from '@/pages/Users/selectors/UserSelector';

import {
  // DictItems,
  // DictItemsTree,
  // Dicts,
  OrgSelector,
  RegionSelector,
  Roles,
  registerSelectors,
} from '@tau/ui';
import { useHistory } from 'react-router';
import SubRouteLayout from './layouts/SubRouteLayout';
import Customer from './pages/Customer';
import Partner from './pages/distribution/Partner';
import Channel from './pages/distribution/Channel';
import Managers from './pages/distribution/Managers';
import Refund from './pages/account/Refund';
import CompanyRoute from './pages/company/CompanyRoute';
import CompanySettingRoute from './pages/company/CompanySettingRoute';
import OrderReport from './pages/report/OrderReport';
import User from './pages/sys/User';
import Log from './pages/sys/Log';
import PV from '@/pages/sys/PV';
import Xcx from './pages/sys/Xcx';
import UserSelector from './pages/sys/User/selectors/UserSelector';
import Feedback from './pages/Feedback';
import DriverGroup from './pages/bob/DriverGroup';
import Member from './pages/bob/Member';
import BobVehicle from './pages/bob/Vehicle';
import BobFeedback from './pages/bob/Feedback';
import OrderView from './pages/single-pages/OrderView';
import CustOrderView from './pages/single-cust-pages/CustOrderView';
import SinglePageLayout from './layouts/SinglePageLayout';
import RefundView from './pages/single-pages/RefundView';
import DictItems from './pages/sys/DictItems';
import DictItemsTree from './pages/sys/DictItemsTree';
import Dicts from './pages/sys/Dicts';
import Rule from './pages/sys/Rule';
import Notify from './pages/sys/Notify';
import Notice from './pages/sys/Notice';
import TaskMap from './pages/task/TaskMap';

// 注册资源和成员选择器
registerSelectors({
  region: RegionSelector,
  org: OrgSelector,
  user: UserSelector,
  userc: UserSelector,
  useri: UserSelector,
});
const routerConfig = [
  {
    path: '/user',
    component: UserLayout,
    children: [
      {
        path: '/login',
        component: Login,
      },
      {
        path: '/phoneLogin',
        component: PhoneLogin,
      },
      {
        path: '/register',
        component: Register,
      },
      {
        path: '/resetpassword',
        component: ResetPassword,
      },
      {
        path: '/',
        redirect: '/user/login',
      },
    ],
  },
  {
    path: '/view',
    component: SinglePageLayout,
    children: [
      {
        path: '/order/:id',
        component: OrderView,
        exact: true,
      },
      {
        path: '/custOrder/:id',
        component: CustOrderView,
        exact: true,
      },
      {
        path: '/order/:id/refund/:refundApplyId',
        component: RefundView,
        exact: true,
      },
    ],
  },
  {
    path: '/',
    component: BasicLayout,
    children: [
      {
        path: '/dashboard',
        component: Dashboard,
      },

      // 订单
      {
        path: '/order/bus',
        component: BusOrder,
      },
      {
        path: '/order/cc',
        component: CcOrder,
      },
      {
        path: '/order/sc',
        component: ScOrder,
      },
      {
        path: '/order/rs',
        component: RsOrder,
      },
      {
        path: '/order/other',
        component: OtherRefund,
      },
      {
        path: '/order/ticket',
        component: Ticket,
      },
      {
        path: '/order/day-cc',
        component: DayCcOrder,
      },

      // 任务
      {
        path: '/task/cc',
        component: CcTask,
      },
      {
        path: '/task/sc',
        component: ScTask,
      },
      {
        path: '/task/rs',
        component: RsTask,
      },
      {
        path: '/task/map',
        component: TaskMap,
      },

      // 价格
      {
        path: '/price/cc',
        component: CcPrice,
      },
      {
        path: '/price/sc',
        component: SubRouteLayout,
        children: [
          {
            path: '/',
            component: ScPrice,
            exact: true,
          },
          {
            path: '/:id/share',
            component: ScSharePrice,
            exact: true,
          },
          {
            path: '/:id/self',
            component: ScSelfPrice,
            exact: true,
          },
          {
            path: '/:id/relevancy',
            component: ScRelevancy,
            exact: true,
          },
        ],
      },
      {
        path: '/price/bus',
        component: BusPrice,
      },
      {
        path: '/price/lineTime',
        component: SubRouteLayout,
        children: [
          {
            path: '/',
            exact: true,
            component: LineTime,
          },
          {
            path: '/:id',
            component: RoadStation,
            exact: true,
          },
        ],
      },
      {
        path: '/price/surcharge',
        component: Surcharge,
      },
      {
        path: '/price/port',
        component: Port,
      },
      {
        path: '/price/region',
        component: Region,
      },
      // {
      //   path: '/price/cc-station',
      //   component: CcStation,
      // },
      {
        path: '/price/cc-station',
        component: SubRouteLayout,
        children: [
          {
            path: '/',
            exact: true,
            component: CcStation,
          },
          {
            path: '/group',
            exact: true,
            component: CcStationGroup,
          },
        ],
      },
      {
        path: '/price/bus-station',
        component: BusStation,
      },
      {
        path: '/price/sc-station',
        component: ScStation,
      },
      {
        path: '/price/otherStation',
        component: OtherStation,
      },

      // 客户管理
      {
        path: '/customer',
        component: Customer,
      },

      // 分销管理
      {
        path: '/distribution',
        component: SubRouteLayout,
        children: [
          {
            path: '/channel',
            exact: true,
            component: Channel,
          },
          {
            path: '/partner',
            exact: true,
            component: Partner,
          },
          {
            path: '/managers',
            exact: true,
            component: Managers,
          },
        ],
      },

      // 承运商
      // {
      //   path: '/company/trip',
      //   component: Trip,
      // },
      {
        path: '/company/info',
        component: SubRouteLayout,
        children: [
          {
            path: '/',
            component: CompanyInfo,
            exact: true,
          },
          {
            path: '/:companyId/route',
            component: CompanyRoute,
            exact: true,
          },
          {
            path: '/:companyId/setting',
            component: CompanySettingRoute,
            exact: true,
          },
        ],
      },
      {
        path: '/company/vehicle',
        component: Vehicle,
      },
      {
        path: '/company/driver',
        component: Driver,
      },
      {
        path: '/company/dispatcher',
        component: Dispatcher,
      },

      // 账务管理

      // {
      //   path: '/account/company',
      //   component: Dashboard,
      // },
      // {
      //   path: '/account/partner',
      //   component: Dashboard,
      // },
      // {
      //   path: '/account/abnormal',
      //   component: Dashboard,
      // },
      {
        path: '/account/refund',
        component: Refund,
      },

      // 营销管理

      {
        path: '/market',
        component: SubRouteLayout,
        children: [
          {
            path: '/activity',
            exact: true,
            component: Activity,
          },
          {
            path: '/activity/:id',
            exact: true,
            component: ActivityCharts,
          },
          {
            path: '/coupon',
            exact: true,
            component: Coupon,
          },
          {
            path: '/scene',
            exact: true,
            component: Scene,
          },
        ],
      },

      // 司机群管理
      {
        path: '/bob',
        component: SubRouteLayout,
        children: [
          {
            path: '/group',
            exact: true,
            component: DriverGroup,
          },
          {
            path: '/member',
            exact: true,
            component: Member,
          },
          {
            path: '/vehicle',
            exact: true,
            component: BobVehicle,
          },
          {
            path: '/feedback',
            exact: true,
            component: BobFeedback,
          },
        ],
      },

      // 用户反馈
      {
        path: '/feedback',
        component: Feedback,
      },

      // 报表统计
      {
        path: '/report/order',
        component: OrderReport,
      },

      // 系统管理
      {
        path: '/sys/role',
        component: Roles,
      },
      {
        path: '/sys/user',
        component: User,
      },
      {
        path: '/sys/pv',
        component: PV,
      },
      {
        path: '/sys/log',
        component: Log,
      },
      {
        path: '/sys/xcx',
        component: Xcx,
      },
      {
        path: '/sys/rule',
        component: Rule,
      },
      {
        path: '/sys/notify',
        component: Notify,
      },
      {
        path: '/sys/notice',
        component: Notice,
      },
      {
        path: '/sys/dicts',
        component: SubRouteLayout,
        children: [
          {
            path: '/',
            exact: true,
            component: Dicts,
          },
          {
            path: '/tree_:dictId',
            exact: true,
            component: DictItemsTreeOverride,
          },
          {
            path: '/:dictId',
            exact: true,
            component: DictItemsOverride,
          },
        ],
      },
      {
        // component: NotFound,
        redirect: '/dashboard',
      },
    ],
  },
];
export default routerConfig;

function DictItemsOverride(props) {
  const history = useHistory();
  return <DictItems onBackClick={() => history.goBack()} {...props} />;
}

function DictItemsTreeOverride(props) {
  const history = useHistory();
  return <DictItemsTree onBackClick={() => history.goBack()} {...props} />;
}
